function login(){
	var userName = $("#user_name").val();
	var password = $("#password").val();
	
	if (!userName) {
		$("#error_message").html("用户名不能为空！").show();
		return;
	}
	if (!password) {
		$("#error_message").html("密码不能为空！").show();
		return;
	}
	
	var param = {user_name:userName, password:password};
	$.getJSON("index/login", param, function(result){
		if (result.status == 1) {
			if ($("#Rememb").attr('checked')) {
				setCookie(userName, password);
			}else {
				removeCookie();
			}
			
			window.open(result.url, "_self");
		}else {
			$("#error_message").html("用户名或密码不正确！").show();
		}
	});
}

function openPage(url){	
	if (url){
		$("#main_body").empty();
		var content = "<div>";
		content += '<iframe id="main" frameborder="0"   src="'+url+'" style="width:100%;height:100%;overflow-x:hidden" onload="autoHeight();"></iframe>';
		content += "</div>";
		$("#main_body").append(content);
	}	
}

function autoHeight(){
	var height = $("#body").height()-10;
	$("#main").height(height);
}

function getCookie(){
	var userName = $.cookie('canyou_user_name');
	var password = $.cookie('canyou_password');
	
	if (userName) {
		$("#user_name").val(userName);
		$("#Rememb").attr("checked", true);
	}
	if (password) {
		$("#password").val(password);
	}
	
}

function setCookie(userName, password){
	$.cookie('canyou_user_name', userName, {expires: 14, path: '/'}); 
	$.cookie('canyou_password', password, {expires: 14, path: '/'}); 
}

function removeCookie() {
	$.cookie('canyou_user_name', null, {path: '/'}); 
	$.cookie('canyou_password', null, {path: '/'}); 
}
